package com.lanou.web.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lanou.service.ShowGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by QuChao on 2018/11/30
 */
@RestController
@RequestMapping("/goods")
public class ShowGoodsController {
    @Autowired
    private ShowGoodsService showGoodsService;

    @RequestMapping("/setItemId")
    public void setItemId() {
        showGoodsService.setItemId();
    }

    @GetMapping("/allGoods")
    public Map<String, Object> showGoods(Integer page, Integer size) {
        Map<String, Object> map = new HashMap<>();
        Page<Object> startPage = PageHelper.startPage(page, size);
        List<Map<String, Object>> list = showGoodsService.findAll();
        long total = startPage.getTotal();
        map.put("total", total);
        map.put("data", list);
        return map;
    }
}
